﻿@{
    ViewData["Title"] = new string[] { "搜索" };
    var keyword = ViewData.Get<string>("keyword", string.Empty);
    var searchType = ViewData.Get<string>("searchType", "All");
}
<div class="row jh-search-home" id="search">
    <div class="col-xs-6 col-xs-offset-3 tn-mb-40">
        <div class="row">
            <div class="col-xs-2 tn-p-xxs">
                <select class="form-control" id="searchType">
                    <option value="All" @(searchType == "All" ? "selected" : "")>全部</option>
                    <option value="Cms" @(searchType == "Cms" ? "selected" : "")>资讯</option>
                    <option value="Thread" @(searchType == "Thread" ? "selected" : "")>贴吧</option>
                    @if (Utility.CheckApplication("Ask"))
                    {
                        <option value="Ask" @(searchType == "Ask" ? "selected" : "")>问答</option>
                    }
                </select>
            </div>
            <div class="col-xs-10 tn-p-xxs">
                <div id="searchForm" class="input-group">
                    <input type="text" id="searchKeyword" name="keyword" class="form-control" value="@keyword">
                    <div class="input-group-btn">
                        <button type="button" class="btn btn-primary btn-search">搜索</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="searchResultList">
        @if (searchType == "All")
        {
            @Html.Action("_SearchAllResult", "Portal", new { keyword = keyword })
        }
        else
        {
            @Html.Action("_SearchResult", "Portal", new { keyword = keyword, searchType = searchType })
        }
    </div>
</div>

<script type="text/javascript">
    require(['jquery'], function ($) {
        //搜索
        $("#search").on('click', '.btn-search', function () {
            var searchType = $("#searchType").val();
            var keyword = $('input[Name="keyword"]').val();
            if (searchType == "All") {
                $.get('@CachedUrlHelper.Action("_SearchAllResult", "Portal")', { keyword: keyword }, function (data) {
                    $("#searchResultList").html(data);
                })
            } else {
                var time = $("#filterTime").val() == null ? "year" : $("#filterTime").val();
                $.get('@CachedUrlHelper.Action("_SearchResult", "Portal")', { keyword: keyword, searchType: searchType, time: time }, function (data) {
                    $("#searchResultList").html(data);
                })
            }
        });

        $("#searchForm").on("keyup", "#searchKeyword", function (ev) {
            if (ev.keyCode == 13) {
                $('#quicksearch').trigger('click');
            }
        })
    })
</script>